package com.hna.cums.web.loginctl;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController { 
	
	/** 日志 */
    static final Logger logger = LoggerFactory.getLogger(LoginController.class);
   
    @RequestMapping("LoginCtl")
    public String LoginCtl(HttpServletRequest request,
    		 HttpServletResponse response) {
    	
    	HttpSession sessionName = request.getSession();
    	try {
			request.setCharacterEncoding("utf-8");
			String UserName = request.getParameter("username");

	    	logger.debug("login user :" + UserName);
	    	sessionName.setAttribute("UserName", UserName);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
    
		return "welcomeView";	
	}
    
    @RequestMapping("logout")
    public String logoutCtl(HttpServletRequest request,
			Model model) {
    	request.getSession().invalidate();
    	return "redirect:/";	
	}
    
}


